//
//  VisitorView.m
//  OC--新浪微博
//
//  Created by Apple on 15/11/9.
//  Copyright © 2015年 Apple. All rights reserved.
//

#import "VisitorView.h"

@interface VisitorView()
//
@property (nonatomic, strong) UIImageView *iconView;
//遮罩图像
@property (nonatomic, strong) UIImageView *maskIconView;
//小房子
@property (nonatomic, strong) UIImageView *homeView;
//文字
@property (nonatomic, strong) UILabel *messageLabel;

@end
@implementation VisitorView
#pragma mark /*******************  更换视图  *******************/
- (void)setUpInfo:(NSString *)imageName title:(NSString *)title {
    self.messageLabel.text = title;
    // 如果图片名称为 nil，说明是首页，直接返回
    if (imageName == nil) {
        self.messageLabel.text = @"关注一些人，回这里看看有什么惊喜";
        [self startAnim];
        return ;
    }
    self.iconView.image = [UIImage imageNamed:imageName];
    self.homeView.hidden = YES;
    [self sendSubviewToBack:self.maskIconView];
}
#pragma mark /*******************  懒加载  *******************/
//懒加载 图标
-(UIImageView *)iconView{
   
    if (_iconView == nil) {
        _iconView = [UIImageView setImageName:@"visitordiscover_feed_image_smallicon"];
;
   }
    return _iconView;
}
//遮罩图像
-(UIImageView *)maskIconView {
    
    if (_maskIconView == nil) {
        _maskIconView = [UIImageView setImageName:@"visitordiscover_feed_mask_smallicon"];
    }
    return _maskIconView;
}
//小房子
//懒加载
-(UIImageView *)homeView {
    
    if (_homeView == nil) {
        _homeView = [UIImageView setImageName:@"visitordiscover_feed_image_house"];
    }
    return _homeView;
}
//文字
//懒加载
-(UILabel *)messageLabel {
    
    if (_messageLabel == nil) {
        _messageLabel = [[UILabel alloc]initLabelTitle:@"关注一些人，回这里看看有什么惊喜" labelFont:14 screenInset:0];
    }
    return _messageLabel;
}
//注册按钮
//懒加载
-(UIButton *)registerButton {
    if (_registerButton == nil) {
        _registerButton = [UIButton setBackImageName:@"common_button_white_disable" title:@"注册" color:[UIColor orangeColor]];
    }
    return _registerButton;
}
//登录按钮
//懒加载
-(UIButton *)LoginButton {
    
    if (_LoginButton == nil) {
        _LoginButton = [UIButton setBackImageName:@"common_button_white_disable" title:@"登录" color:[UIColor darkGrayColor]];
    }
    return _LoginButton;
}

#pragma mark /*******************  构造方法  *******************/
//重写构造方法
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setUpUI];
     
    }
    return self;
}
#pragma mark /*******************  动画  *******************/
- (void)startAnim {
    CABasicAnimation *anim = [[CABasicAnimation alloc]init];
    anim.keyPath = @"transform.rotation";
    anim.toValue = @(2 * M_PI);
    anim.repeatCount = MAXFLOAT;
    anim.duration = 40;
   // 用在不断重复的动画上，当动画绑定的图层对应的视图被销毁，动画会自动被销毁
    anim.removedOnCompletion = NO;
    [self.iconView.layer addAnimation:anim forKey:nil];
}
//MARK: - 自动布局子控件
- (void)setUpUI {
    [self addSubview:self.iconView];
   [self addSubview:self.maskIconView];
    [self addSubview:self.homeView];
    [self addSubview:self.messageLabel];
    [self addSubview:self.registerButton];
    [self addSubview:self.LoginButton];
    //1.图标
    [self.iconView makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.centerY.equalTo(self);}];
    //2.遮罩
    [self.maskIconView makeConstraints:^(MASConstraintMaker *make) {
        make.top.right.left.equalTo(self);
        make.bottom.equalTo(self.registerButton);
    }];
    //3.小房子
    [self.homeView makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.centerY.equalTo(self.iconView);
    }];
    //4.信息
    [self.messageLabel makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.iconView.bottom).offset(16);
        make.centerX.equalTo(self.iconView);
        make.width.equalTo(224);
        make.height.equalTo(36);
    }];
    //注册
    [self.registerButton makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.messageLabel);
        make.top.equalTo(self.messageLabel.bottom);
        make.width.equalTo(100);
        make.height.equalTo(36);
    }];
    //注册
    [self.LoginButton makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.messageLabel);
        make.top.width.height.equalTo(self.registerButton);
    }];
    self.backgroundColor = [[UIColor alloc]initWithWhite:237.0 / 255.0 alpha:1.0];
}
@end
